package cn.wolfcode.luowowo.common.util;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.Calendar;
import java.util.Date;

public class LocalDateTimeUtil {
    public static Integer getRemainSecondsOneDay(Date currentDate) {
        LocalDateTime midnight = LocalDateTime.ofInstant(currentDate.toInstant(), ZoneId.systemDefault())
                                                                                        .plusDays(1)
                                                                                        .withHour(0)
                                                                                        .withMinute(0)
                                                                                        .withSecond(0)
                                                                                        .withNano(0);
        LocalDateTime currentDateTime = LocalDateTime.ofInstant(currentDate.toInstant(), ZoneId.systemDefault());
        long seconds = ChronoUnit.SECONDS.between(currentDateTime, midnight);
        return (int) seconds;
    }

    public static String dateToWeekday(Date changeDate){
        String[] weekdays = { "周日", "周一", "周二", "周三", "周四", "周五", "周六" };
        if(changeDate == null) {
            throw new RuntimeException("传入时间为Null");
        }
        Calendar cal = Calendar.getInstance();
        cal.setTime(changeDate);
        int numOfWeek = cal.get(Calendar.DAY_OF_WEEK) - 1;
        return weekdays[numOfWeek];
    }
}
